<?php
if(isset($_REQUEST["list"]))
{
	$dir = opendir("./objects");
	$items = array();
	while($item = readdir($dir))
	{
		if($item[0] != '.')
		{
			$items[] = '"'.str_replace(array("\\", '"'), array("\\\\", '\\"'), $item).'"';
		}
	}
	echo '['.join(', ', $items).']';
	exit;
}
?>
<html>
<head>
<title>Object editor</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="./js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="./js/jcanvas.min.js"></script>
<script type="text/javascript" src="./js/main.js"></script>
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<body>

<script type="text/javascript">
	$(window).ready(function(){
		init();
	});
</script>

	<div id="head"><div id="content"><h1>Object editor</h1><i>For STR engine</i></div></div>
	<div id="wrap">
		<div id="content">
		<table id="layout">
		<tr>
			<td id="toolbar-box" colspan="2">
				<div class="icon load has-popup" id="load">
					<div class="popup" id="load-popup">
						<script type="text/javascript">
							function onShow()
							{
								$('#file-list').empty();
								$('#file-list').html('Loading...');
								$.getJSON('?list', function(data){
									$('#file-list').empty();
									for(key in data)
									{
										var name = data[key];
										var a = $('<a>').addClass('file-url').attr('href', 'javascript:loadObject(\'./objects/'+name+'\')').html(name).click(function(){
//											console.log(name);
//											loadObject('./objects/'+name);
										});
										$('#file-list').append(a);
									}
								});
//								$('#file-list').getJSON();
							}
						</script>
						<div id="file-list">Loading...</div>
					</div>
				</div>
				<div class="icon save" onClick="saveObject()"></div>
				<div class="icon about" onClick="alert('If you don`t know what`s this, get the hell out of here.')"></div>
				<div class="icon params has-popup" id="params">
					<div class="popup" id="params-popup">
						<table width="100%">
<!--							<tr>
								<td>Object name:</td>
								<td><input type="text" name="object-name" id="object-name" value="" /></td>
							</tr>-->
							<tr>
								<td>Grid size:</td>
								<td><input type="text" name="grid-size" id="grid-size" value="16" /></td>
							</tr>
						</table>
					</div>
				</div>
			</td>
		</tr>
		<tr>
			<td id="canvas-box" valign="top">
				<canvas id="canvas" width="640px" height="480px"></canvas>
			</td>
			<td id="property-box" valign="top">
				<div id="properties"><p>Loading...</p></div>
			</td>
		</tr>
		</table>
		</div>
	</div>

</body>
</html>
